﻿Imports System.IO
Imports Infragistics.Win.AppStyling
Imports Infragistics.Win.AppStyling.Runtime

''' <summary>
''' Form chính của chương trình
''' </summary>
''' <remarks>Nguyễn Huy Thường added on 04/05/2011</remarks>
Public Class frmMain

    ''' <summary>
    ''' Biến lưu lại tình trạng đăng nhập
    ''' </summary>
    ''' <remarks>Nguyễn Huy Thường added on 06/07/2012</remarks>
    Private m_eLogin As clscommon.LoginStatus
    Public Property LoginStatus() As clscommon.LoginStatus
        Get
            Return m_eLogin
        End Get
        Set(ByVal value As clscommon.LoginStatus)
            m_eLogin = value
        End Set
    End Property

#Region "Method"

    ''' <summary>
    ''' Sub hiển thị form con
    ''' </summary>
    ''' <param name="frmData">form kế thừa từ baseList</param>
    ''' <remarks>Nguyễn Huy Thường added on 04/05/2011</remarks>
    Private Sub ShowForm(ByVal frmData As frmBaseList)
        Me.CloseAllChildForm()
        With frmData
            .MdiParent = Me
            .WindowState = FormWindowState.Maximized
            .Show()
        End With
    End Sub

    ''' <summary>
    ''' Sub đóng tất cả các form con hiện đang được mở
    ''' </summary>
    ''' <remarks>Nguyễn Huy Thường added on 04/05/2011</remarks>
    Private Sub CloseAllChildForm()
        For Each frmChild As Form In Me.MdiChildren
            frmChild.Close()
        Next
    End Sub
#End Region

#Region "Event"

    ''' <summary>
    ''' Hiển thị form đăng nhập sau khi form main load xong
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks>Nguyễn Huy Thường added on 06/07/2012</remarks>
    Private Sub frmMain_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
        Try
            If clscommon.DecodingData(My.Settings.Crrthm) <> String.Empty And FileIO.FileSystem.FileExists(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\Style\" + clscommon.DecodingData(My.Settings.Crrthm)) Then
                StyleManager.Load(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\Style\" + clscommon.DecodingData(My.Settings.Crrthm))
            End If
            LoginStatus = clscommon.LoginStatus.NotLoggedIn
            My.Settings.Crrrl = String.Empty
            Dim loginForm As New frmLogin
            loginForm.LoginStatus = Me.LoginStatus
            loginForm.ShowDialog(Me)
        Catch ex As Exception
            clscommon.ShowException(ex.Message)
        End Try
    End Sub

    ''' <summary>
    ''' Refresh form main nếu form resize
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks>Nguyễn Huy Thường added on 06/07/2012</remarks>
    Private Sub frmMain_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        Try
            Me.Refresh()
        Catch ex As Exception
            clscommon.ShowException(ex.Message)
        End Try
    End Sub

    ''' <summary>
    ''' Xác định hành động khi click vào một item trên toolbar
    ''' </summary>
    ''' <remarks>Nguyễn Huy Thường added on 04/06/2011</remarks>
    Private Sub tbmMain_ToolClick(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinToolbars.ToolClickEventArgs) Handles tbmMain.ToolClick
        Try
            Select Case e.Tool.Key
                Case "System"

                Case "Manage"

                Case "About"

                Case "ChangeTheme"
                    Dim changeThemeDialog As New dlgChangeTheme
                    changeThemeDialog.ShowDialog()
                Case "ChangePassword"

                Case "Logout"
                    CloseAllChildForm()
                    Dim loginForm As New frmLogin
                    loginForm.ShowDialog(Me)
                Case "Employee"
                    Dim frmEmployee As New frmEmployeeList
                    ShowForm(frmEmployee)
                Case "Store"
                    Dim frmItem As New frmItemList
                    ShowForm(frmItem)
                Case "Shipment"
                    Dim frmShipment As New frmShipmentList
                    ShowForm(frmShipment)
                Case "Invoice"
                    Dim frmInvoice As New frmInvoiceList
                    ShowForm(frmInvoice)
                Case "Customer"
                    Dim frmCustomer As New frmCustomerList
                    ShowForm(frmCustomer)

                Case "Help"

                Case "AboutFMS"

                Case "Mail"

                Case "Exit"

            End Select
        Catch ex As Exception
            clscommon.ShowException(ex.Message)
        End Try
    End Sub

    ''' <summary>
    ''' Xác định hành động khi một item trên side bar được click
    ''' </summary>
    ''' <remarks>Nguyễn Huy Thường added on 25/02/2012</remarks>
    Private Sub exbCommand_ActiveItemChanged(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinExplorerBar.ItemEventArgs) Handles exbCommand.ActiveItemChanged
        Try
            Select Case e.Item.Key
                Case "System"

                Case "Manage"

                Case "About"

                Case "ChangeTheme"

                Case "ChangePassword"

                Case "Employee"
                    Dim frmEmployee As New frmEmployeeList
                    ShowForm(frmEmployee)
                Case "Store"
                    Dim frmItem As New frmItemList
                    ShowForm(frmItem)
                Case "Shipment"
                    Dim frmShipment As New frmShipmentList
                    ShowForm(frmShipment)
                Case "Invoice"
                    Dim frmInvoice As New frmInvoiceList
                    ShowForm(frmInvoice)
                Case "Customer"
                    Dim frmCustomer As New frmCustomerList
                    ShowForm(frmCustomer)
                Case "Partner"
                    Dim frmPartner As New frmPartnerList
                    ShowForm(frmPartner)
                Case "Help"

                Case "AboutFMS"

                Case "Mail"

                Case "Exit"

            End Select
        Catch ex As Exception
            clscommon.ShowException(ex.Message)
        End Try
    End Sub

    ''' <summary>
    ''' Xóa RoleName khi exit
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks>Nguyễn Huy Thường added</remarks>
    Private Sub frmMain_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        Try
            My.Settings.Crrrl = String.Empty
        Catch ex As Exception
            clscommon.ShowException(ex.Message)
        End Try
    End Sub
#End Region
End Class